<template>
	<view class="modal-mask" v-if="visible" @click="close">
		<view class="modal-container" @click.stop>
			<view class="modal-header">
				<text class="modal-title">直播介绍</text>
				<text class="modal-close" @click="close">×</text>
			</view>
			<view class="modal-content">
				<textarea class="intro-textarea" placeholder="直播介绍可以更好的帮助观众了解您的直播内容" v-model="introContent"
					maxlength="100" @input="handleInput"></textarea>
				<text class="word-count">{{ wordCount }}/100</text>
			</view>
			<view class="modal-footer">
				<button class="confirm-btn" @click="confirm">确定</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			visible: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				introContent: '',
				wordCount: 0
			}
		},
		methods: {
			close() {
				this.$emit('close');
			},
			confirm() {
				this.$emit('confirm', this.introContent);
				this.close();
			},
			handleInput(e) {
				this.wordCount = e.detail.value.length;
			}
		}
	}
</script>

<style lang="scss">
	.modal-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: flex-end;
		z-index: 999;
	}

	.modal-container {
		width: 100%;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		padding: 30rpx;
		box-sizing: border-box;
		animation: slide-up 0.3s;
	}

	@keyframes slide-up {
		from {
			transform: translateY(100%);
		}

		to {
			transform: translateY(0);
		}
	}

	.modal-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.modal-title {
		font-size: 36rpx;
		font-weight: bold;
	}

	.modal-close {
		font-size: 50rpx;
		color: #999;
	}

	.modal-content {
		margin-bottom: 30rpx;
	}

	.intro-textarea {
		width: 100%;
		height: 300rpx;
		padding: 20rpx;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}

	.word-count {
		font-size: 24rpx;
		color: #999;
		text-align: right;
		display: block;
	}

	.modal-footer {
		display: flex;
		justify-content: center;
	}

	.confirm-btn {
		width: 80%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #55aaff;
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
		border: none;
	}
</style>